<?php
class tags extends spController
{
	function index_premium()
	{
		$callback = spAccess('r',  'ad_tmp_result');
		if($callback['use_count']>0 && $callback['nums'] - $callback['use_count'] <= 0) {
			return false;
		}		
	
		if(!$callback) {
			$m_ecrm = spClass('m_ecrm');
			$result = $m_ecrm->find(array('isfront'=>1), 'activity_id DESC');
			if(!$result) return false; //如果没有优惠券，则不显示
			
			if($result['activity_id']) $result['premium_url'] = spUrl('signup', 'get_ecrm', array('activity_id'=>$result['activity_id'])); //转化活动id
			
			if($result['store_id']) {
				$m_taobao = spClass('m_taobao');
				$tbshopconvert = new TaobaokeShopsConvertRequest;
				$tbshopconvert->setFields("click_url,shop_type");
				$tbshopconvert->setSids($result['store_id']);
				$tbshopconvert->setNick("半价汇");
				$convert_resp = $m_taobao->m_topsdk->execute($tbshopconvert);
				$result['storelink'] = $convert_resp->taobaoke_shops->taobaoke_shop[0]->click_url;
			}
			$result['valid_date'] = '有效日期：' . datetoch($result['startdate']) . '-' . datetoch($result['enddate']);
			$callback = $result;
			spAccess('w',  'ad_tmp_result', $result, 86400);
		}
		$callback['use_count'] = $callback['use_count'] ? $callback['use_count'] : 0;
		$callback['isget'] = 0;
		if($_SESSION['visitor_id'] > 0 && $callback) { //判断是否已经领取优惠券，如果已经领取则不显示
			$m_premium_user = spClass('m_premium_user');
			if($m_premium_user->find(array('visitor_id'=>$_SESSION['visitor_id'], 'activity_id'=>$callback['activity_id']))) {
				$callback['isget'] = 1;
			}
			$callback['use_count'] = $m_premium_user->findCount(array('activity_id'=>$callback['activity_id']));
		}
		
		exit(json_encode($callback));
	}
}